package com.zh.lex;

import java.util.Objects;

public class Token {
	
	private String type;
    private String value;

    private int startIndex; // 开始的位置
    private int endIndex;  // 结束的位置
    private int line; // 第几行 \n 换行

	public Token(String type, String value, int startIndex, int endIndex, int line) {
        this.type = type;
        this.value = value;
        this.startIndex = startIndex;
        this.endIndex = endIndex;
        this.line = line;
    }

    public Token() {}

    public void setType(String type) {
        this.type = type;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public Token setEndIndex(int endIndex) {
        this.endIndex = endIndex;
        return this;
    }

    public void setLine(int line) {
        this.line = line;
    }

    public String getType() {
        return type;
    }

    public String getValue() {
        return value;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public int getEndIndex() {
        return endIndex;
    }

    public int getLine() {
        return line;
    }

    @Override
    public String toString() {
        return type  +  "_" + value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Token token = (Token) o;
        return Objects.equals(type, token.type) && Objects.equals(value, token.value);
    }

    @Override
    public int hashCode() {
        return Objects.hash(type, value);
    }
}
